layui.use(['table', 'form', 'vip_table', 'jquery', 'fms_util', 'element'], function () {
    // 操作对象
    var form = layui.form,
        table = layui.table,
        vipTable = layui.vip_table,
        fmsUtil = layui.fms_util,
        element = layui.element,
        $ = layui.jquery;

    //表格加载
    var where = {};
    where[API.key.userId] = API.userId();
    where[API.key.systemSourceId] = API.systemSourceId();

    var tableIns = {};
    initTable(where);
    function initTable(where) {
        tableIns = vipTable.bdTable({
            table: table,
            elem: "#dataTable",
            limit: 6,
            cols: [[
                {type: 'numbers', title: '序',width:'5%', align: 'center'},
                {field: 'mark', title: '告警标识', align: 'center'},
                {field: 'alarmName', title: '告警名称', align: 'center'},
                {field: 'level', title: '告警级别', align: 'center'},
                {field: 'alarmReason', title: '告警原因', align: 'center'},
                {title: '操作', align: 'center', toolbar: '#barOption'}
                ]],
            data:[
                {mark:"1",alarmName:"2",level:"3",alarmReason:"4"},
                {mark:"1",alarmName:"2",level:"3",alarmReason:"4"},
                {mark:"1",alarmName:"2",level:"3",alarmReason:"4"},
                {mark:"1",alarmName:"2",level:"3",alarmReason:"4"}
            ]
        });
    }

    //搜索
    form.on('submit(search)', function (data) {
        where = $.extend(where, data.field);
        var reloadWhere = fmsUtil.filterObject(where);//筛选掉空的数据
        where.pageNo = 1;
        tableIns.reload({
            searchState: true,
            where: reloadWhere
        });
        return false;
    });

    table.on('tool(dataTable)', function (obj) {
        var layEvent = obj.event;
        var value = obj.value,//得到修改后的值
            data = obj.data,//得到所在行所有键值
            field = obj.field; //得到字段
console.log(data)
        if (layEvent === 'edit') {
            active.edit(data);
        }
    });

    var active = {
        edit: function (liatData) {
            fmsUtil.showAjaxDiag({
                url: pathUrl + "/html/alarm/box/library-edit.html",
                title: "修改",
                area: ['400px', 'auto'],
                offset: '20%',
                onSuccess: function (layero, index, form) {
                    console.log(liatData)
                    $(layero).find('input[name="alarmName"]').val(liatData.alarmName);
                    $(layero).find('input[name="alarmReason"]').val(liatData.alarmReason);
                    //弹窗里的提交
                    form.on('submit(submit)', function (data) {
                        // console.log(data)

                        fmsUtil.msg("操作成功", {
                            callBack: function () {
                                parent.layer.close(index);
                                tableIns.reload();
                            }
                        });
                    });

                    //弹窗里的返回
                    $(layero).find('#closeBox').on('click', function () {
                        parent.layer.close(index);
                    });
                }
            });
        },
    };


    //导出按钮
    $('button.export').on('click',function(){
        parent.parent.layer.confirm('是否确定导出？', {icon: 3, title:'提示'}, function(index){
            fmsUtil.doAjax({
                action: exportAction[showIndex],
                data: {systemSourceId:API.systemSourceId()},
                load: false,
                type: 'get',
                success: function (result) {
                    console.log(result);
                    if (result.isSuccess) {
                        window.open(result.data);
                        /*fmsUtil.msg('导出成功',{callBack:function(){
                            tableIns1.reload();
                        }});*/
                    }else{
                        fmsUtil.msg(result.description);
                    }
                }
            });
            layer.close(index);
        });
        return false;
    });

});